package fl.ass.service.interceptor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogInterceptor {
	
	private static final Logger logger = LoggerFactory.getLogger(LogInterceptor.class);
	
	//切入点要拦截的类
	@Pointcut("execution (* fl.ass.service.api..*.*(..))")
	private void log(){}
	
	/**  
     * Before 
     * 在核心业务执行前执行，不能阻止核心业务的调用。 
     * @param joinPoint  
     */    
    @Before("log()")    
    public void beforeAdvice(JoinPoint joinPoint) {    
    	logger.info("start execute "+joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
    }  
      
    /**  
     * After  
     * 核心业务逻辑退出后（包括正常执行结束和异常退出），执行此Advice 
     * @param joinPoint 
     */  
    @After("log()")    
    public void afterAdvice(JoinPoint joinPoint) {    
    	logger.info("end execute "+joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName()); 
    }    

}
